package applet.source;

//
//  FilterExtension.java
//  TestAppletXcode
//
//  Created by Thibaud PIQUET on 25/03/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

import java.io.File;
import javax.swing.*;
import javax.swing.filechooser.*;

/**
 *
 * @author Thibaud PIQUET
 */
public class FilterExtension extends FileFilter
{
	String extension;
	String description;

	public FilterExtension(String extension, String description) {
		if (extension.indexOf('.') == -1) {
			extension = "." + extension;
		}

		this.extension = extension;
		this.description = description;
	}

    public boolean accept(File file) {

		if (file.getName().endsWith(extension)) {
			return true;
		}
		else if (file.isDirectory()) {
			return true;
		}
		return false;
	}

	public String getDescription() {
		return this.description + "(*" + extension + ")";
	}
	
	public String getExtension() {
		return extension;
	}
}